import { createRouter, createWebHistory } from 'vue-router'

// 创建router,可以实现跳转
const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    //name不能重复
    { path: '/', redirect: '/login' },
    {
      path: '/manager',
      component: () => import('../views/Manager.vue'),
      meta: { title: "管理页面" },
      children: [
        { path: 'home', name: 'home', meta: { title: "主页" }, component: () => import('../views/Home.vue') },
        { path: 'employee', name: 'employee', meta: { title: "员工管理" }, component: () => import('../views/Employee.vue') },
        { path: 'password', name: 'password', meta: { title: "修改密码" }, component: () => import('../views/Password.vue') },
        // 新增宠物管理系统相关路由
        { path: 'customer', name: 'customer', meta: { title: "客户管理" }, component: () => import('../views/CustomerManagement.vue') },
        { path: 'service', name: 'service', meta: { title: "宠物服务管理" }, component: () => import('../views/PetServiceManagement.vue') },
        { path: 'inventory', name: 'inventory', meta: { title: "商品管理" }, component: () => import('../views/InventoryManagement.vue') },
        { path: 'finance', name: 'finance', meta: { title: "财务管理" }, component: () => import('../views/FinanceManagement.vue') },
        { path: 'marketing', name: 'marketing', meta: { title: "营销管理" }, component: () => import('../views/MarketingManagement.vue') },
        { path: 'system', name: 'system', meta: { title: "系统设置" }, component: () => import('../views/SystemSettings.vue') },
        { path: 'dataAnalysis', name: 'dataAnalysis', meta: { title: "数据分析" }, component: () => import('../views/CustomerSelfService.vue') },
      ]
    },
    { path: '/login', name: 'login', meta: { title: "登录页面" }, component: () => import('../views/Login.vue') },
    { path: '/register', name: 'register', meta: { title: "注册页面" }, component: () => import('../views/Register.vue') },
    { path: '/404', name: 'NotFound', meta: { title: "找不到页面" }, component: () => import('../views/404.vue') },
    //路由输错时统一到达 404 页面
    { path: '/:pathMatch(.*)', redirect: '/404' },
  ],
})

//beforeEach 标识跳转前的一些操作
router.beforeEach((to, from, next) => {
  document.title = to.meta.title  //把页面的title修改成meta中定义的
  next()  //必须写
})

export default router
